package com.hexacta.radio.controller;

import com.hexacta.radio.model.Dial;
import com.hexacta.radio.model.IObserver;
import com.hexacta.radio.model.Radio;
import com.hexacta.radio.persistence.RadioRepository;
import com.hexacta.radio.view.RadioView;

public class Controller implements IObserver {

	private RadioView view;
	private Radio radio;
	private RadioRepository radioRepository;

	public Controller(RadioRepository radioRepository) {
		
		this.radioRepository = radioRepository;
		this.radio = radioRepository.getRadio();
		this.radio.addObserver(this);
		
		// Radio View
		this.view = new RadioView(this);
		this.view.updateDisplay(this.radio.getStringDial());
		this.view.setVisible(true);
	}

	@Override
	public void update() {
		this.view.updateDisplay(this.radio.getStringDial());
	}

	public void turnRadioOnOff(boolean radioOn) {
		this.radio.turnRadioOnOff(radioOn);
	}

	public void dialDown() {
		this.radio.dialDown();
	}

	public void dialUp() {
		this.radio.dialUp();
	}

	public void seekDown() {
		this.radio.seekDown();
	}

	public void seekUp() {
		this.radio.seekUp();
	}

	public void addDialToFavourites() {
		
	}

	public void editSelectedDial() {
		Dial selectedDial = this.radio.getSelectedDial();
		this.view.showEditDial(selectedDial.getDial());
	}

	public void acceptEditDial(String dial, String name) {
		this.radio.updateDial(dial, name);
		this.view.closeEditDial();
	}

	public void cancelEditDial() {
		this.view.closeEditDial();
	}

}
